package com.probiz.estoresa.system.web.action.shipping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.system.Carrier;
import com.probiz.estore.common.model.system.ShippingMethod;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.system.service.CarrierManager;
import com.probiz.estore.system.service.ShippingMethodManager;

public class ShippingMethodController extends GenericStoreAdminController<ShippingMethod> {
	private ShippingMethodManager shippingMethodManager = null;
	private CarrierManager carrierManager = null;
	private static final String	CARRIER_LIST	= "carrierList";
	
	public void setShippingMethodManager(ShippingMethodManager inMgr) {
		this.shippingMethodManager = inMgr;
	}

	public void setCarrierManager(CarrierManager carrierManager) {
		this.carrierManager = carrierManager;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(ShippingMethod entity) {
		return entity.getShippingMethodName();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = shippingMethodManager;

	}
	
	@Override
	protected Map<String,String> getSortMap(){
		Map<String,String> sortMap = new HashMap<String,String>();
		sortMap.put("1", "convert_gbk(shippingMethodName)");
		sortMap.put("3", "convert_gbk(carrier.carrierName)");
		sortMap.put("4", "status");
		return sortMap;
	}
	
	@Override
	protected ShippingMethod formBackingObject(HttpServletRequest request) {
		// 获取激活的运输公司列表
		List<Carrier> carrierList = this.carrierManager.findActiveCarriers();
		request.setAttribute(CARRIER_LIST, carrierList);
		return super.formBackingObject(request);
	}


	@Override
	public ModelAndView multiDelete(HttpServletRequest request,
			HttpServletResponse response) {
		super.multiDelete(request, response);
		return getRedirectToActionView("defaultAction");
	}
	
	@Override
	protected void preSave(HttpServletRequest request, ShippingMethod entity, BindException errors) {
	}

}
